home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1990-1992 by Michael Davidson.
- * All rights reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for any purpose and without fee is hereby
- * granted, provided that the above copyright notice appear in all
- * copies and that both that copyright notice and this permission
- * notice appear in supporting documentation.
- *
- * This software is provided "as is" without express or implied warranty.
- */
-
- /*
- * vga.c - support routines for generic IBM VGA
- */
-
- #include "video.h"
- #include "vdev.h"
- #include "vga.h"
-
- /*
- * table of video modes supported for generic VGA
- */
- static vmode_t vga_modes[] =
- {
- { 320, 200, 8, V_MODE_SUPPORTED | V_GRAPHICS_MODE },
- { 80, 25, 0, V_MODE_SUPPORTED | V_TEXT_MODE },
- { 0, 0, 0, 0 }
- };
-
- static int vga_bios_mode[] =
- {
- 0x13,
- 0x03,
- 0x00
- };
-
- static int vga_bios_initial_mode = -1;
- static vmode_t *vga_mode;
- static unsigned char *VGAGraphicsAddress;
- static unsigned char *VGATextAddress;
-
- /*
- * vga_reset()
- */
- static void
- vga_reset()
- {
- if (vga_bios_initial_mode != -1)
- VBiosSetMode(vga_bios_initial_mode);
- }
-
- /*
- * vga_setmode()
- */
- static int
- vga_setmode(
- int i
- )
- {
- vmode_t *m;
-
- m = &vga_modes[i];
-
- VBiosSetMode(vga_bios_mode[i] | 0x80);
- if ((VBiosGetMode() & 0x7f) != vga_bios_mode[i])
- return -1;
-
- if (m->depth == 0) /* text mode */
- {
- VBiosDisableBlink();
- VBiosSetCursorPosition(m->width, m->height);
- }
- vga_mode = m;
- return 0;
- }
-
- /*
- * vga_setpalette()
- */
- static void
- vga_setpalette(
- color_t *colormap,
- int ncolors
- )
- {
- int i;
-
- inb(0x3da);
- for (i = 0; i < 16; i++)
- {
- outb(0x3c0, i);
- outb(0x3c0, i);
- }
-
- inb(0x3da);
- outb(0x3c8, 0);
- while (--ncolors >= 0)
- {
- outb(0x3c9, RGB8Lookup[0][colormap->red] >> 2);
- outb(0x3c9, RGB8Lookup[1][colormap->green] >> 2);
- outb(0x3c9, RGB8Lookup[2][colormap->blue] >> 2);
- colormap++;
- }
- outb(0x3c0, 0x20);
- }
-
- static void
- vga_putpixels8(
- int x,
- int y,
- unsigned char *pixels,
- int npixels
- )
- {
- unsigned offset;
-
- offset = (long)y * vga_mode->width + x;
-
- memcpy(VGAGraphicsAddress + offset, pixels, npixels);
- }
-
- static void
- vga_putpixels24(
- int x,
- int y,
- unsigned char *pixels,
- int npixels
- )
- {
- unsigned offset;
-
- offset = (long)y * vga_mode->width + x;
-
- CopyPixels24to8(pixels, VGAGraphicsAddress + offset, npixels, VPixelLookup);
- }
-
- /*
- * vga_puttext()
- */
- static void
- vga_puttext(
- int x,
- int y,
- register char *buf,
- int nbytes
- )
- {
- memcpy(VGATextAddress + ((y * vga_mode->width + x) * 2), buf, nbytes);
- }
-
-
- static void
- vga_clear(
- int bg
- )
- {
- int n;
-
- n = vga_mode->width * vga_mode->height;
-
- if (vga_mode->depth == 0) /* text mode */
- memset(VGATextAddress, bg | (bg << 4), n * 2);
- else
- memset(VGAGraphicsAddress, bg, n);
- }
-
- /*
- * vga_init() - one time initialisation
- */
- /*ARGSUSED*/
- int
- vga_init(
- char *name,
- struct vdev *v
- )
- {
- v->v_name = "VGA";
- v->v_modes = vga_modes;
- v->v_init = vga_init;
- v->v_reset = vga_reset;
- v->v_setmode = vga_setmode;
- v->v_setpalette = vga_setpalette;
- v->v_clear = vga_clear;
- v->v_putpixels8 = vga_putpixels8;
- v->v_putpixels24 = vga_putpixels24;
- v->v_puttext = vga_puttext;
-
- VGAGraphicsAddress = (unsigned char *) 0xA0000;
- VGATextAddress = (unsigned char *) 0xB8000;
-
- vga_bios_initial_mode = VBiosGetMode();
-
- return 0;
- }
-
- int
- vga_probe()
- {
- return 0;
- }
-